#
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# Contains rewriters for zetasql analyzers.

load("@rules_cc//cc:cc_library.bzl", "cc_library")
load("@rules_cc//cc:cc_test.bzl", "cc_test")

package(
    default_visibility = ["//zetasql/base:zetasql_implementation"],
)

cc_library(
    name = "rewriter_relevance_checker",
    srcs = ["rewriter_relevance_checker.cc"],
    hdrs = ["rewriter_relevance_checker.h"],
    deps = [
        "//zetasql/base:ret_check",
        "//zetasql/base:status",
        "//zetasql/public:builtin_function_cc_proto",
        "//zetasql/public:function_headers",
        "//zetasql/public:options_cc_proto",
        "//zetasql/public:sql_function",
        "//zetasql/public:sql_tvf",
        "//zetasql/public:sql_view",
        "//zetasql/public:templated_sql_function",
        "//zetasql/public:templated_sql_tvf",
        "//zetasql/resolved_ast",
        "//zetasql/resolved_ast:resolved_node_kind_cc_proto",
        "@com_google_absl//absl/container:btree",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
    ],
)

cc_library(
    name = "flatten_rewriter",
    srcs = ["flatten_rewriter.cc"],
    hdrs = ["flatten_rewriter.h"],
    deps = [
        "//zetasql/base:ret_check",
        "//zetasql/base:status",
        "//zetasql/public:analyzer_options",
        "//zetasql/public:analyzer_output_properties",
        "//zetasql/public:catalog",
        "//zetasql/public:options_cc_proto",
        "//zetasql/public:rewriter_interface",
        "//zetasql/public:value",
        "//zetasql/public/types",
        "//zetasql/resolved_ast",
        "//zetasql/resolved_ast:column_factory",
        "//zetasql/resolved_ast:resolved_ast_enums_cc_proto",
        "//zetasql/resolved_ast:rewrite_utils",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/types:span",
    ],
)

cc_library(
    name = "with_expr_rewriter",
    srcs = ["with_expr_rewriter.cc"],
    hdrs = ["with_expr_rewriter.h"],
    deps = [
        "//zetasql/base:ret_check",
        "//zetasql/base:status",
        "//zetasql/public:analyzer_options",
        "//zetasql/public:analyzer_output_properties",
        "//zetasql/public:catalog",
        "//zetasql/public:rewriter_interface",
        "//zetasql/public/types",
        "//zetasql/resolved_ast",
        "//zetasql/resolved_ast:column_factory",
        "//zetasql/resolved_ast:rewrite_utils",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
    ],
)

cc_library(
    name = "row_type_rewriter",
    srcs = ["row_type_rewriter.cc"],
    hdrs = ["row_type_rewriter.h"],
    deps = [
        "//zetasql/base:check",
        "//zetasql/base:map_util",
        "//zetasql/base:ret_check",
        "//zetasql/base:status",
        "//zetasql/public:analyzer_options",
        "//zetasql/public:catalog",
        "//zetasql/public:function_headers",
        "//zetasql/public:options_cc_proto",
        "//zetasql/public:rewriter_interface",
        "//zetasql/public/types",
        "//zetasql/resolved_ast",
        "//zetasql/resolved_ast:column_factory",
        "//zetasql/resolved_ast:resolved_ast_builder",
        "//zetasql/resolved_ast:resolved_ast_rewrite_visitor",
        "//zetasql/resolved_ast:rewrite_utils",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/types:span",
    ],
)

cc_library(
    name = "sql_function_inliner",
    srcs = ["sql_function_inliner.cc"],
    hdrs = ["sql_function_inliner.h"],
    deps = [
        "//zetasql/base:map_util",
        "//zetasql/base:ret_check",
        "//zetasql/base:status",
        "//zetasql/base:varsetter",
        "//zetasql/common:errors",
        "//zetasql/public:analyzer_options",
        "//zetasql/public:analyzer_output_properties",
        "//zetasql/public:catalog",
        "//zetasql/public:function",
        "//zetasql/public:parse_location",
        "//zetasql/public:rewriter_interface",
        "//zetasql/public:sql_function",
        "//zetasql/public:sql_tvf",
        "//zetasql/public:templated_sql_function",
        "//zetasql/public:templated_sql_tvf",
        "//zetasql/public:value",
        "//zetasql/public/types",
        "//zetasql/resolved_ast",
        "//zetasql/resolved_ast:column_factory",
        "//zetasql/resolved_ast:resolved_ast_builder",
        "//zetasql/resolved_ast:resolved_ast_enums_cc_proto",
        "//zetasql/resolved_ast:resolved_ast_rewrite_visitor",
        "//zetasql/resolved_ast:resolved_node_kind_cc_proto",
        "//zetasql/resolved_ast:rewrite_utils",
        "@com_google_absl//absl/cleanup",
        "@com_google_absl//absl/container:btree",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/memory",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/types:span",
    ],
)

cc_library(
    name = "sql_view_inliner",
    srcs = ["sql_view_inliner.cc"],
    hdrs = ["sql_view_inliner.h"],
    deps = [
        "//zetasql/base:check",
        "//zetasql/base:ret_check",
        "//zetasql/base:status",
        "//zetasql/public:analyzer_options",
        "//zetasql/public:analyzer_output_properties",
        "//zetasql/public:catalog",
        "//zetasql/public:options_cc_proto",
        "//zetasql/public:rewriter_interface",
        "//zetasql/public:sql_view",
        "//zetasql/public/types",
        "//zetasql/resolved_ast",
        "//zetasql/resolved_ast:column_factory",
        "//zetasql/resolved_ast:resolved_ast_enums_cc_proto",
        "//zetasql/resolved_ast:rewrite_utils",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings:str_format",
    ],
)

cc_library(
    name = "map_function_rewriter",
    srcs = ["map_function_rewriter.cc"],
    hdrs = ["map_function_rewriter.h"],
    deps = [
        "//zetasql/analyzer:builtin_only_catalog",
        "//zetasql/analyzer:substitute",
        "//zetasql/base:ret_check",
        "//zetasql/base:status",
        "//zetasql/public:analyzer_options",
        "//zetasql/public:analyzer_output_properties",
        "//zetasql/public:builtin_function_cc_proto",
        "//zetasql/public:catalog",
        "//zetasql/public:function",
        "//zetasql/public:options_cc_proto",
        "//zetasql/public:rewriter_interface",
        "//zetasql/public:type",
        "//zetasql/public:value",
        "//zetasql/resolved_ast",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
    ],
)

cc_library(
    name = "match_recognize_function_rewriter",
    srcs = ["match_recognize_function_rewriter.cc"],
    hdrs = ["match_recognize_function_rewriter.h"],
    deps = [
        "//zetasql/base:ret_check",
        "//zetasql/public:analyzer_options",
        "//zetasql/public:analyzer_output_properties",
        "//zetasql/public:builtin_function_cc_proto",
        "//zetasql/public:catalog",
        "//zetasql/public:function",
        "//zetasql/public:options_cc_proto",
        "//zetasql/public:rewriter_interface",
        "//zetasql/public:type",
        "//zetasql/resolved_ast",
        "//zetasql/resolved_ast:resolved_ast_rewrite_visitor",
        "//zetasql/resolved_ast:rewrite_utils",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
    ],
)

cc_library(
    name = "typeof_function_rewriter",
    srcs = ["typeof_function_rewriter.cc"],
    hdrs = ["typeof_function_rewriter.h"],
    deps = [
        "//zetasql/base:ret_check",
        "//zetasql/base:status",
        "//zetasql/public:analyzer_options",
        "//zetasql/public:analyzer_output_properties",
        "//zetasql/public:builtin_function_cc_proto",
        "//zetasql/public:catalog",
        "//zetasql/public:function",
        "//zetasql/public:language_options",
        "//zetasql/public:options_cc_proto",
        "//zetasql/public:rewriter_interface",
        "//zetasql/public:value",
        "//zetasql/public/types",
        "//zetasql/resolved_ast",
        "//zetasql/resolved_ast:resolved_ast_builder",
        "//zetasql/resolved_ast:resolved_ast_rewrite_visitor",
        "//zetasql/resolved_ast:rewrite_utils",
        "@com_google_absl//absl/status:statusor",
    ],
)

cc_library(
    name = "unpivot_rewriter",
    srcs = ["unpivot_rewriter.cc"],
    hdrs = ["unpivot_rewriter.h"],
    deps = [
        "//zetasql/base:ret_check",
        "//zetasql/base:status",
        "//zetasql/public:analyzer_options",
        "//zetasql/public:analyzer_output_properties",
        "//zetasql/public:builtin_function_cc_proto",
        "//zetasql/public:catalog",
        "//zetasql/public:function",
        "//zetasql/public:function_cc_proto",
        "//zetasql/public:id_string",
        "//zetasql/public:options_cc_proto",
        "//zetasql/public:rewriter_interface",
        "//zetasql/public/types",
        "//zetasql/resolved_ast",
        "//zetasql/resolved_ast:rewrite_utils",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/types:span",
    ],
)

cc_library(
    name = "pivot_rewriter",
    srcs = ["pivot_rewriter.cc"],
    hdrs = ["pivot_rewriter.h"],
    deps = [
        "//zetasql/analyzer:resolver",
        "//zetasql/analyzer:substitute",
        "//zetasql/base:check",
        "//zetasql/base:ret_check",
        "//zetasql/base:status",
        "//zetasql/common:aggregate_null_handling",
        "//zetasql/public:analyzer_options",
        "//zetasql/public:analyzer_output_properties",
        "//zetasql/public:builtin_function_cc_proto",
        "//zetasql/public:catalog",
        "//zetasql/public:function",
        "//zetasql/public:language_options",
        "//zetasql/public:options_cc_proto",
        "//zetasql/public:rewriter_interface",
        "//zetasql/public:value",
        "//zetasql/public/annotation:collation",
        "//zetasql/public/types",
        "//zetasql/resolved_ast",
        "//zetasql/resolved_ast:column_factory",
        "//zetasql/resolved_ast:resolved_ast_enums_cc_proto",
        "//zetasql/resolved_ast:resolved_node_kind_cc_proto",
        "//zetasql/resolved_ast:rewrite_utils",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/types:span",
    ],
)

cc_library(
    name = "nulliferror_function_rewriter",
    srcs = ["nulliferror_function_rewriter.cc"],
    hdrs = ["nulliferror_function_rewriter.h"],
    deps = [
        "//zetasql/base:ret_check",
        "//zetasql/base:status",
        "//zetasql/public:analyzer_options",
        "//zetasql/public:analyzer_output_properties",
        "//zetasql/public:builtin_function_cc_proto",
        "//zetasql/public:catalog",
        "//zetasql/public:function",
        "//zetasql/public:options_cc_proto",
        "//zetasql/public:rewriter_interface",
        "//zetasql/public:value",
        "//zetasql/public/types",
        "//zetasql/resolved_ast",
        "//zetasql/resolved_ast:resolved_ast_builder",
        "//zetasql/resolved_ast:resolved_ast_rewrite_visitor",
        "//zetasql/resolved_ast:rewrite_utils",
        "@com_google_absl//absl/status:statusor",
    ],
)

cc_library(
    name = "measure_type_rewriter",
    srcs = [
        "measure_type_rewriter.cc",
        # The utility files should be private to this target.
        "measure_type_rewriter_util.cc",
        "measure_type_rewriter_util.h",
        "measure_collector.cc",
        "measure_collector.h",
        "measure_source_scan_rewrite_util.cc",
        "measure_source_scan_rewrite_util.h",
        "measure_reference_rewrite_util.cc",
        "measure_reference_rewrite_util.h",
    ],
    hdrs = [
        "measure_type_rewriter.h",
    ],
    deps = [
        "//zetasql/base:check",
        "//zetasql/base:ret_check",
        "//zetasql/base:status",
        "//zetasql/base:strings",
        "//zetasql/common:measure_utils",
        "//zetasql/public:analyzer_options",
        "//zetasql/public:builtin_function_cc_proto",
        "//zetasql/public:catalog",
        "//zetasql/public:function_headers",
        "//zetasql/public:language_options",
        "//zetasql/public:options_cc_proto",
        "//zetasql/public:rewriter_interface",
        "//zetasql/public/types",
        "//zetasql/resolved_ast",
        "//zetasql/resolved_ast:column_factory",
        "//zetasql/resolved_ast:resolved_ast_builder",
        "//zetasql/resolved_ast:resolved_ast_rewrite_visitor",
        "//zetasql/resolved_ast:rewrite_utils",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/cleanup",
        "@com_google_absl//absl/container:btree",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/memory",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
    ],
)

cc_library(
    name = "is_first_is_last_function_rewriter",
    srcs = ["is_first_is_last_function_rewriter.cc"],
    hdrs = ["is_first_is_last_function_rewriter.h"],
    deps = [
        "//zetasql/base:ret_check",
        "//zetasql/base:status",
        "//zetasql/public:analyzer_options",
        "//zetasql/public:analyzer_output_properties",
        "//zetasql/public:builtin_function_cc_proto",
        "//zetasql/public:catalog",
        "//zetasql/public:function_headers",
        "//zetasql/public:options_cc_proto",
        "//zetasql/public:rewriter_interface",
        "//zetasql/public/types",
        "//zetasql/resolved_ast",
        "//zetasql/resolved_ast:column_factory",
        "//zetasql/resolved_ast:resolved_ast_builder",
        "//zetasql/resolved_ast:resolved_ast_rewrite_visitor",
        "//zetasql/resolved_ast:rewrite_utils",
        "@com_google_absl//absl/status:statusor",
    ],
)

cc_library(
    name = "registration",
    srcs = ["registration.cc"],
    hdrs = ["registration.h"],
    deps = [
        "//zetasql/base:check",
        "//zetasql/base:logging",
        "//zetasql/public:options_cc_proto",
        "@com_google_absl//absl/base:core_headers",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/synchronization",
    ],
)

cc_library(
    name = "like_any_all_rewriter",
    srcs = ["like_any_all_rewriter.cc"],
    hdrs = ["like_any_all_rewriter.h"],
    deps = [
        "//zetasql/analyzer:substitute",
        "//zetasql/base:ret_check",
        "//zetasql/base:status",
        "//zetasql/public:analyzer_options",
        "//zetasql/public:analyzer_output_properties",
        "//zetasql/public:builtin_function_cc_proto",
        "//zetasql/public:catalog",
        "//zetasql/public:function_headers",
        "//zetasql/public:rewriter_interface",
        "//zetasql/public/types",
        "//zetasql/resolved_ast",
        "//zetasql/resolved_ast:column_factory",
        "//zetasql/resolved_ast:rewrite_utils",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
    ],
)

cc_library(
    name = "builtin_function_inliner",
    srcs = ["builtin_function_inliner.cc"],
    hdrs = ["builtin_function_inliner.h"],
    deps = [
        "//zetasql/analyzer:builtin_only_catalog",
        "//zetasql/analyzer:substitute",
        "//zetasql/base:ret_check",
        "//zetasql/base:status",
        "//zetasql/public:analyzer_options",
        "//zetasql/public:analyzer_output_properties",
        "//zetasql/public:catalog",
        "//zetasql/public:function_headers",
        "//zetasql/public:options_cc_proto",
        "//zetasql/public:rewriter_interface",
        "//zetasql/public/types",
        "//zetasql/resolved_ast",
        "//zetasql/resolved_ast:rewrite_utils",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
    ],
)

cc_test(
    name = "registration_test",
    srcs = ["registration_test.cc"],
    deps = [
        ":registration",
        "//zetasql/base/testing:zetasql_gtest_main",
        "//zetasql/public:analyzer_options",
        "//zetasql/public:options_cc_proto",
        "//zetasql/public:rewriter_interface",
        "//zetasql/resolved_ast",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
    ],
)

cc_library(
    name = "grouping_set_rewriter",
    srcs = ["grouping_set_rewriter.cc"],
    hdrs = ["grouping_set_rewriter.h"],
    deps = [
        "//zetasql/base:check",
        "//zetasql/base:map_util",
        "//zetasql/base:ret_check",
        "//zetasql/base:status",
        "//zetasql/public:analyzer_options",
        "//zetasql/public:analyzer_output_properties",
        "//zetasql/public:catalog",
        "//zetasql/public:options_cc_proto",
        "//zetasql/public:rewriter_interface",
        "//zetasql/public/types",
        "//zetasql/resolved_ast",
        "//zetasql/resolved_ast:resolved_ast_builder",
        "//zetasql/resolved_ast:resolved_ast_rewrite_visitor",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/memory",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
    ],
)

cc_library(
    name = "insert_dml_values_rewriter",
    srcs = ["insert_dml_values_rewriter.cc"],
    hdrs = ["insert_dml_values_rewriter.h"],
    deps = [
        "//zetasql/base:no_destructor",
        "//zetasql/base:ret_check",
        "//zetasql/base:status",
        "//zetasql/public:analyzer_options",
        "//zetasql/public:analyzer_output_properties",
        "//zetasql/public:catalog",
        "//zetasql/public:options_cc_proto",
        "//zetasql/public:rewriter_interface",
        "//zetasql/public:sql_view",
        "//zetasql/public/types",
        "//zetasql/resolved_ast",
        "//zetasql/resolved_ast:column_factory",
        "//zetasql/resolved_ast:resolved_ast_builder",
        "//zetasql/resolved_ast:resolved_ast_rewrite_visitor",
        "//zetasql/resolved_ast:resolved_node_kind_cc_proto",
        "@com_google_absl//absl/status:statusor",
    ],
)

cc_library(
    name = "multiway_unnest_rewriter",
    srcs = ["multiway_unnest_rewriter.cc"],
    hdrs = ["multiway_unnest_rewriter.h"],
    deps = [
        "//zetasql/base:check",
        "//zetasql/base:ret_check",
        "//zetasql/base:status",
        "//zetasql/public:analyzer_options",
        "//zetasql/public:catalog",
        "//zetasql/public:function_headers",
        "//zetasql/public:rewriter_interface",
        "//zetasql/public:value",
        "//zetasql/public/functions:array_zip_mode_cc_proto",
        "//zetasql/public/types",
        "//zetasql/resolved_ast",
        "//zetasql/resolved_ast:column_factory",
        "//zetasql/resolved_ast:make_node_vector",
        "//zetasql/resolved_ast:resolved_ast_builder",
        "//zetasql/resolved_ast:resolved_ast_rewrite_visitor",
        "//zetasql/resolved_ast:rewrite_utils",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/types:span",
    ],
)

cc_library(
    name = "update_constructor_rewriter",
    srcs = ["update_constructor_rewriter.cc"],
    hdrs = ["update_constructor_rewriter.h"],
    deps = [
        "//zetasql/public:analyzer_options",
        "//zetasql/public:analyzer_output_properties",
        "//zetasql/public:catalog",
        "//zetasql/public:rewriter_interface",
        "//zetasql/public/types",
        "//zetasql/resolved_ast",
        "//zetasql/resolved_ast:resolved_ast_rewrite_visitor",
        "@com_google_absl//absl/status:statusor",
    ],
)

cc_library(
    name = "variadic_function_signature_expander",
    srcs = ["variadic_function_signature_expander.cc"],
    hdrs = ["variadic_function_signature_expander.h"],
    deps = [
        "//zetasql/base:ret_check",
        "//zetasql/base:status",
        "//zetasql/public:analyzer_options",
        "//zetasql/public:analyzer_output_properties",
        "//zetasql/public:builtin_function_cc_proto",
        "//zetasql/public:catalog",
        "//zetasql/public:function_cc_proto",
        "//zetasql/public:function_headers",
        "//zetasql/public:options_cc_proto",
        "//zetasql/public:rewriter_interface",
        "//zetasql/public/types",
        "//zetasql/resolved_ast",
        "//zetasql/resolved_ast:resolved_ast_builder",
        "//zetasql/resolved_ast:resolved_ast_rewrite_visitor",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
    ],
)

cc_library(
    name = "anonymization_helper",
    srcs = ["anonymization_helper.cc"],
    hdrs = ["anonymization_helper.h"],
    deps = [
        "//zetasql/analyzer:expr_matching_helpers",
        "//zetasql/analyzer:resolver",
        "//zetasql/analyzer/rewriters/privacy:approx_count_distinct_utility",
        "//zetasql/analyzer/rewriters/privacy:privacy_utility",
        "//zetasql/base",
        "//zetasql/base:check",
        "//zetasql/base:ret_check",
        "//zetasql/base:status",
        "//zetasql/common:status_payload_utils",
        "//zetasql/proto:anon_output_with_report_cc_proto",
        "//zetasql/proto:internal_error_location_cc_proto",
        "//zetasql/public:analyzer_options",
        "//zetasql/public:anon_function",
        "//zetasql/public:anonymization_utils",
        "//zetasql/public:builtin_function",
        "//zetasql/public:builtin_function_cc_proto",
        "//zetasql/public:catalog",
        "//zetasql/public:function",
        "//zetasql/public:function_cc_proto",
        "//zetasql/public:id_string",
        "//zetasql/public:language_options",
        "//zetasql/public:options_cc_proto",
        "//zetasql/public:parse_location",
        "//zetasql/public:rewriter_interface",
        "//zetasql/public:strings",
        "//zetasql/public:type",
        "//zetasql/public:type_cc_proto",
        "//zetasql/public:value",
        "//zetasql/public:with_modifier_mode",
        "//zetasql/public/functions:differential_privacy_cc_proto",
        "//zetasql/public/types",
        "//zetasql/resolved_ast",
        "//zetasql/resolved_ast:column_factory",
        "//zetasql/resolved_ast:make_node_vector",
        "//zetasql/resolved_ast:resolved_ast_builder",
        "//zetasql/resolved_ast:resolved_ast_enums_cc_proto",
        "//zetasql/resolved_ast:resolved_node_kind_cc_proto",
        "//zetasql/resolved_ast:rewrite_utils",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/memory",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
    ],
)

cc_library(
    name = "anonymization_rewriter",
    srcs = [
        "anonymization_rewriter.cc",
    ],
    hdrs = ["anonymization_rewriter.h"],
    deps = [
        ":anonymization_helper",
        "//zetasql/base:ret_check",
        "//zetasql/base:status",
        "//zetasql/public:analyzer_options",
        "//zetasql/public:catalog",
        "//zetasql/public:rewriter_interface",
        "//zetasql/public/types",
        "//zetasql/resolved_ast",
        "//zetasql/resolved_ast:column_factory",
        "@com_google_absl//absl/base:core_headers",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/status:statusor",
    ],
)

cc_library(
    name = "aggregation_threshold_rewriter",
    srcs = [
        "aggregation_threshold_rewriter.cc",
    ],
    hdrs = ["aggregation_threshold_rewriter.h"],
    deps = [
        ":anonymization_helper",
        "//zetasql/base:ret_check",
        "//zetasql/base:status",
        "//zetasql/public:analyzer_options",
        "//zetasql/public:catalog",
        "//zetasql/public:rewriter_interface",
        "//zetasql/resolved_ast",
        "//zetasql/resolved_ast:column_factory",
        "//zetasql/resolved_ast:rewrite_utils",
        "@com_google_absl//absl/status:statusor",
    ],
)

cc_library(
    name = "pipe_assert_rewriter",
    srcs = ["pipe_assert_rewriter.cc"],
    hdrs = ["pipe_assert_rewriter.h"],
    deps = [
        "//zetasql/base:ret_check",
        "//zetasql/base:status",
        "//zetasql/public:analyzer_options",
        "//zetasql/public:catalog",
        "//zetasql/public:function_headers",
        "//zetasql/public:rewriter_interface",
        "//zetasql/public:value",
        "//zetasql/public/types",
        "//zetasql/resolved_ast",
        "//zetasql/resolved_ast:resolved_ast_builder",
        "//zetasql/resolved_ast:resolved_ast_rewrite_visitor",
        "//zetasql/resolved_ast:rewrite_utils",
        "@com_google_absl//absl/status:statusor",
    ],
)

cc_library(
    name = "pipe_describe_rewriter",
    srcs = ["pipe_describe_rewriter.cc"],
    hdrs = ["pipe_describe_rewriter.h"],
    deps = [
        "//zetasql/base:ret_check",
        "//zetasql/base:status",
        "//zetasql/public:rewriter_interface",
        "//zetasql/public:value",
        "//zetasql/public/types",
        "//zetasql/resolved_ast",
        "//zetasql/resolved_ast:column_factory",
        "//zetasql/resolved_ast:resolved_ast_builder",
        "//zetasql/resolved_ast:resolved_ast_rewrite_visitor",
        "//zetasql/resolved_ast:rewrite_utils",
        "@com_google_absl//absl/status:statusor",
    ],
)

cc_library(
    name = "rewrite_subpipeline",
    srcs = ["rewrite_subpipeline.cc"],
    hdrs = ["rewrite_subpipeline.h"],
    deps = [
        "//zetasql/base:ret_check",
        "//zetasql/base:status",
        "//zetasql/resolved_ast",
        "//zetasql/resolved_ast:resolved_ast_rewrite_visitor",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
    ],
)

cc_library(
    name = "pipe_if_rewriter",
    srcs = ["pipe_if_rewriter.cc"],
    hdrs = ["pipe_if_rewriter.h"],
    deps = [
        ":rewrite_subpipeline",
        "//zetasql/base:status",
        "//zetasql/public:rewriter_interface",
        "//zetasql/resolved_ast",
        "//zetasql/resolved_ast:resolved_ast_builder",
        "//zetasql/resolved_ast:resolved_ast_rewrite_visitor",
        "//zetasql/resolved_ast:rewrite_utils",
        "@com_google_absl//absl/status:statusor",
    ],
)

cc_test(
    name = "pipe_if_rewriter_test",
    srcs = ["pipe_if_rewriter_test.cc"],
    deps = [
        ":pipe_if_rewriter",
        "//zetasql/base/testing:status_matchers",
        "//zetasql/base/testing:zetasql_gtest_main",
        "//zetasql/public:analyzer_options",
        "//zetasql/public:analyzer_output_properties",
        "//zetasql/public:id_string",
        "//zetasql/public:simple_catalog",
        "//zetasql/public/types",
        "//zetasql/resolved_ast",
        "@com_google_absl//absl/status:statusor",
    ],
)

cc_library(
    name = "generalized_query_stmt_rewriter",
    srcs = ["generalized_query_stmt_rewriter.cc"],
    hdrs = ["generalized_query_stmt_rewriter.h"],
    deps = [
        "//zetasql/base:check",
        "//zetasql/base:ret_check",
        "//zetasql/base:status",
        "//zetasql/public:rewriter_interface",
        "//zetasql/resolved_ast",
        "//zetasql/resolved_ast:resolved_ast_builder",
        "//zetasql/resolved_ast:resolved_ast_rewrite_visitor",
        "//zetasql/resolved_ast:resolved_node_kind_cc_proto",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
    ],
)

cc_library(
    name = "subpipeline_stmt_rewriter",
    srcs = ["subpipeline_stmt_rewriter.cc"],
    hdrs = ["subpipeline_stmt_rewriter.h"],
    deps = [
        ":rewrite_subpipeline",
        "//zetasql/base:check",
        "//zetasql/base:status",
        "//zetasql/public:rewriter_interface",
        "//zetasql/resolved_ast",
        "//zetasql/resolved_ast:resolved_ast_builder",
        "//zetasql/resolved_ast:resolved_node_kind_cc_proto",
        "@com_google_absl//absl/status:statusor",
    ],
)

cc_library(
    name = "order_by_and_limit_in_aggregate_rewriter",
    srcs = ["order_by_and_limit_in_aggregate_rewriter.cc"],
    hdrs = ["order_by_and_limit_in_aggregate_rewriter.h"],
    deps = [
        "//zetasql/base:ret_check",
        "//zetasql/base:status",
        "//zetasql/public:analyzer_options",
        "//zetasql/public:analyzer_output_properties",
        "//zetasql/public:builtin_function_cc_proto",
        "//zetasql/public:catalog",
        "//zetasql/public:options_cc_proto",
        "//zetasql/public:rewriter_interface",
        "//zetasql/public:value",
        "//zetasql/public/types",
        "//zetasql/resolved_ast",
        "//zetasql/resolved_ast:column_factory",
        "//zetasql/resolved_ast:resolved_ast_builder",
        "//zetasql/resolved_ast:resolved_ast_rewrite_visitor",
        "//zetasql/resolved_ast:rewrite_utils",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/memory",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/types:span",
    ],
)

cc_library(
    name = "templated_function_call_rewriter",
    srcs = ["templated_function_call_rewriter.cc"],
    hdrs = ["templated_function_call_rewriter.h"],
    deps = [
        ":rewriter_relevance_checker",
        "//zetasql/base",
        "//zetasql/base:ret_check",
        "//zetasql/base:status",
        "//zetasql/public:analyzer_options",
        "//zetasql/public:catalog",
        "//zetasql/public:options_cc_proto",
        "//zetasql/public:templated_sql_function",
        "//zetasql/public:templated_sql_tvf_no_resolver",
        "//zetasql/resolved_ast",
        "//zetasql/resolved_ast:column_factory",
        "//zetasql/resolved_ast:resolved_ast_rewrite_visitor",
        "//zetasql/resolved_ast:resolved_node_kind_cc_proto",
        "//zetasql/resolved_ast:rewrite_utils",
        "@com_google_absl//absl/container:btree",
        "@com_google_absl//absl/status:statusor",
    ],
)

cc_test(
    name = "templated_function_call_rewriter_test",
    srcs = ["templated_function_call_rewriter_test.cc"],
    deps = [
        "//zetasql/base/testing:status_matchers",
        "//zetasql/base/testing:zetasql_gtest_main",
        "//zetasql/public:analyzer",
        "//zetasql/public:analyzer_options",
        "//zetasql/public:builtin_function_options",
        "//zetasql/public:function_cc_proto",
        "//zetasql/public:function_headers",
        "//zetasql/public:options_cc_proto",
        "//zetasql/public:rewriter_interface",
        "//zetasql/public:simple_catalog",
        "//zetasql/public:templated_sql_function",
        "//zetasql/public/types",
    ],
)
